home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / usr_-_Usr_Files / BIN / SVGAKEYM.{CA < prev    next >
Encoding:
Text File  |  1999-09-17  |  2.6 KB  |  99 lines

  1. #!/usr/bin/perl
  2. #
  3. # svgakeymap - by Brion Vibber (brion@pobox.com), 6/30 - 7/3/1998
  4. # Generates a keymap conversion file for svgalib from two keytable definitions.
  5. #
  6. # Usage:
  7. #   svgakeymap [physical_map [program_map]] > output.keymap
  8. #
  9. # The conversion map is output to stdout; you may wish to redirect it.
  10. # Keymaps are searched for in /usr/lib/kbd/keytables and are automatically
  11. # filtered through gzip if necessary.
  12. #
  13. # Read the file README.keymap from the svgalib distribution for more info.
  14.  
  15. $ktd = "/usr/lib/kbd/keytables/";
  16. if(scalar(@ARGV) > 0) {
  17.     $inmap = $ARGV[0];
  18. } else {
  19.     $inmap = "us";
  20. }
  21. if(scalar(@ARGV) > 1) {
  22.     $outmap = $ARGV[1];
  23. } else {
  24.     $outmap = $inmap;
  25. }
  26.     
  27.  
  28. foreach $bob ($inmap, $outmap) {
  29.     #print "$bob\n";
  30.     unless(-e $bob) {
  31.         # Tack the keytable dir on it
  32.         $bob = $ktd . $bob;
  33.         #print "$bob\n";
  34.  
  35.         unless(-e $bob) {
  36.             # Tack a .gz on it
  37.             $bob .= ".map";
  38.             #print "$bob\n";
  39.             
  40.             unless(-e $bob) {
  41.                 # Tack a .gz on it
  42.                 $bob .= ".gz";
  43.                 #print "$bob\n";
  44.                 
  45.                 unless(-e $bob) {
  46.                     die "Couldn't find $bob\n.";
  47.                 }
  48.             }
  49.         }
  50.     }
  51. }
  52.  
  53. if($inmap =~ m/\.gz$/) {
  54.     # Filter thru gzip
  55.     open INMAP, "gzip -dc $inmap |" or die "Could not open $inmap!\n";
  56. } else {
  57.     open INMAP, "<$inmap" or die "Could not open $inmap!\n";
  58. }
  59.  
  60. if($outmap =~ m/\.gz$/) {
  61.     # Filter thru gzip
  62.     open OUTMAP, "gzip -dc $outmap |" or die "Could not open $outmap!\n";
  63. } else {
  64.     open OUTMAP, "<$outmap" or die "Could not open $outmap!\n";
  65. }
  66.  
  67. print "# This is a svgalib scancode conversion map generated by svgakeymap.\n",
  68.       "# Read the file README.keymap from the svgalib distribution for more info.\n#\n",
  69.       "# Physical keyboard layout: $inmap\n",
  70.       "# Program's expected keyboard layout: $outmap\n#\n",
  71.       "# physical_scancode program_scancode key_name\n";
  72.  
  73.  
  74. while($kc = <OUTMAP>) {
  75.     if($kc =~ m/^keycode\s+([0-9]+)\s*\=\s*(\S+)/) {
  76.         # Store scancodes and names for future reference
  77.         #print stderr "- $1 - $2 -\n";
  78.         $keys{$1} = $2;
  79.         $keys{$2} = $1;
  80.     } else {
  81.         # We ignore anything else - including modifiers
  82.     }
  83. }
  84.  
  85. while($kc = <INMAP>) {
  86.     if($kc =~ m/^keycode\s+([0-9]+)\s*\=\s*(\S+)/) {
  87.         if($keys{$2}) {
  88.             # Matching scancodes!
  89.             #unless($keys{$1} eq $2) {
  90.                 # Find the other code with the same key...
  91.                 #print "$1 $keys{$2}\t# $keys{$1} <-> $2\n";
  92.             #print "$1 $keys{$2}\t# $2\n";
  93.             print "$1 $keys{$2} $2\n";
  94.                 #}
  95.         }
  96.     }
  97. }
  98.  
  99.